<?php
  defined('_JEXEC') or die('Restricted access');
 
  if($this->params->get('showlogin') == 1) {
     $document	= &JFactory::getDocument();
	 $renderer	= $document->loadRenderer('module');

     $module = JModuleHelper::getModule('login');
     $module->showtitle = 0;
     $module->content = null;
     if(isset($module) && @$module->id){
         $module->params	= $this->loadModuleParams();
         echo $renderer->render($module,array("style"=>""));
     }
  }

?>


<?php
    $this->params->def('greeting', 1);
    //$return	= modJarpxnowHelper::getReturnURL($params, $type);
    $usecurl = $this->params->get( 'usecurl', 1 );
    $api_key = $this->params->get('apikey');
    $user =& JFactory::getUser();
    $type 	= (!$user->get('guest')) ? 'logout' : 'login';
    $return = $this->get_ReturnURL();
    if($type == "login") {
?>

<?php

  $post_data = array('apiKey' => $api_key);
 
  if (function_exists('curl_init')) {
  	  
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_URL, 'https://rpxnow.com/plugin/lookup_rp');
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    $raw_json = curl_exec($curl);
    curl_close($curl);
  } else if(ini_get ( 'allow_url_fopen' ) && extension_loaded("openssl") ){
  	        
	        $raw_json = @file_get_contents ( "https://rpxnow.com/plugin/lookup_rp?apiKey=" . $post_data ['apiKey'] . "&&format=json" ); 			
  } else {
  	         
			JError::raiseWarning ( 1, JText::_ ( 'Sorry, but your server does not currently support open method. Please contact the network administrator system for help' ).'.' );
			return;
  }
  
  // parse the json response into an associative array
  $json = json_decode($raw_json, true);
  
  $realm = $json['realm'];
  //$realm = "dathq-test.rpxnow.com";
  $tokenurl = JURI::base();
  
?>

<div style="position: relative;left:15px">
<p>
  <?php echo JText::_('Or Login with your:'); ?>
</p>
<input type="hidden" name="apiKey" value="<?php echo $api_key;?>" />
<a class="rpxnow" style="text-decoration: none" onclick="return false;"
   href="https://<?php echo $realm; ?>/openid/v2/signin?token_url=<?php echo $tokenurl;?>">
      <img width="55" src="plugins/system/plg_jarpxnow/images/google.png" alt="RPX"/>
</a>
<a class="rpxnow" style="text-decoration: none" onclick="return false;"
   href="https://<?php echo $realm; ?>/openid/v2/signin?token_url=<?php echo $tokenurl;?>">
   <img width="55" src="plugins/system/plg_jarpxnow/images/twitter.png" alt="RPX"/>
</a>
<a class="rpxnow" style="text-decoration: none" onclick="return false;"
   href="https://<?php echo $realm; ?>/openid/v2/signin?token_url=<?php echo $tokenurl;?>">
   <img style="position: relative;top:2px" width="55" src="plugins/system/plg_jarpxnow/images/openid.png" alt="RPX"/>
</a>
<a class="rpxnow" style="text-decoration: none" onclick="return false;"
   href="https://<?php echo $realm; ?>/openid/v2/signin?token_url=<?php echo $tokenurl;?>">
   <img style="position: relative;top:2px" width="55" src="plugins/system/plg_jarpxnow/images/spacel.png" alt="RPX"/>
</a>
<a class="rpxnow" style="text-decoration: none" onclick="return false;"
   href="https://<?php echo $realm; ?>/openid/v2/signin?token_url=<?php echo $tokenurl;?>">
   <img width="55" src="plugins/system/plg_jarpxnow/images/login.png" alt="RPX"/>
</a>
<a class="rpxnow" style="text-decoration: none" onclick="return false;"
   href="https://<?php echo $realm; ?>/openid/v2/signin?token_url=<?php echo $tokenurl;?>">
   <img style="position: relative;top:2px" width="55" src="plugins/system/plg_jarpxnow/images/facebook.png" alt="RPX"/>
</a>      
</div>

<script src="https://rpxnow.com/openid/v2/widget"
        type="text/javascript"></script>
		
<script type="text/javascript">
  RPXNOW.token_url = "<?php echo $tokenurl ?>";
  RPXNOW.realm = "<?php echo $realm; ?>";
  RPXNOW.overlay = true;
  RPXNOW.default_provider = "openid";
  RPXNOW.language_preference = 'en';
  RPXNOW.flags="show_provider_list";
  RPXNOW.flags="hide_sign_in_with";
</script>

<?php }  ?>